package raspberry_pi_app;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import bradz.media_server.raspberry_pi_app.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ActivityMessage extends Activity{
	
	private ClassUberLogger logger;
	private ApplicationGlobalVars globals;
	private ClassNetworkHelper helper;
	
	/*Handler myHandler = new Handler() {

  	    @Override
  	    public void handleMessage(Message msg) {
  	        switch (msg.what) {
  	        case 1337:
  	        	TextView chat_box = (TextView) findViewById(R.id.chat_box);
  	        	chat_box.append("\n" + msg.arg1);
  	            break;
  	        default:
  	            break;
  	        }
  	    }
  	};*/
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_message);
	    logger = new ClassUberLogger("ActivityHome");
	    globals = ((ApplicationGlobalVars) this.getApplication());
	    helper = new ClassNetworkHelper(this,globals);
	    init_buttons();
	}
	
	public void init_buttons(){
		
		final EditText text = (EditText) findViewById(R.id.message_box);
		
		Button submit_button = (Button) findViewById(R.id.submit_button);
		submit_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	logger.info("Sending Message: " + text.getText().toString());
            	List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        		pairs.add(new BasicNameValuePair("message", text.getText().toString()));
        		pairs.add(new BasicNameValuePair("type", "text"));
        		pairs.add(new BasicNameValuePair("payload", globals.get_developer_payload()));
        		helper.send_message(pairs,"message_text/");
        		text.setText("");
            }
        });
	}
}
